/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package horde.internalResources.horrorControl.HCvis;

import horde.internalResources.HorrorControl.HorrorControl;
import horde.internalResources.dictionaries.dictionary;
import horde.utils.iconFactory.iconFactory;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

/**
 * Component that manages the  graphic interface for the HorrorControl
 * @author Arturo Mazón
 * @author Andres Picazo
 */

public class horrorControlGraphics extends JPanel {
   
    // <editor-fold defaultstate="collapsed" desc="constructoras">
    private synchronized static void createInstance() {
        if (instance == null) {
            instance = new horrorControlGraphics();
        }
    }

    private synchronized static void createInstance(HorrorControl hc) {
        if (instance == null) {
            instance = new horrorControlGraphics(hc);

        }
    }

    public static horrorControlGraphics getInstance() {
        if (instance == null) {
            createInstance();
            HorrorControl.getInstance();
        }
        return instance;
    }

    public static horrorControlGraphics getInstance(HorrorControl hc) {
        if (instance == null) {
            createInstance(hc);
        }
        return instance;
    }

    private horrorControlGraphics() {
        super();
        createElements();
        organizeElements();
        this.setSize(tamPanel);
        this.setVisible(true);
    }

    private horrorControlGraphics(HorrorControl hc) {
        super();
        this.hc = hc;
        createElements();
        organizeElements();
        this.setSize(tamPanel);
        this.setVisible(true);
    }
// </editor-fold>

    /**
     * Creates all the components necessary to build the graphic interface
     */
    private void createElements() {
        paneles = new JTabbedPane();
        pTraces = (tracesPanel) tracesPanel.getInstance(hc);
//        pTraces = new tracesPanel(hc);
        pDebug = new debugPanel(hc);
        pExc = new exceptionPanel(hc);
        pLoader = new  loaderPanel(hc);
        pStats = new  statsPanel(hc);
        paneles.addTab(dictionary.getString("hcVis.traces"), ic.getIcon("iconTraces[32x32].PNG"), pTraces);
        paneles.addTab(dictionary.getString("hcVis.debug"), ic.getIcon("iconDepur[32x32].PNG"), pDebug);
//        paneles.addTab(dictionary.getString("hcVis.exceptions"), ic.getIcon("iconException[32x32].PNG"), pExc);
//        paneles.addTab(dictionary.getString("hcVis.loader"), ic.getIcon("iconLoader[32x32].PNG"), pLoader);
//        paneles.addTab(dictionary.getString("hcVis.Stats"), ic.getIcon("iconStats[32x32].PNG"), pStats);
    }

    /**
     * Places properly each component in the graphic interface
     */
    private void organizeElements() {
        this.setLayout(new BorderLayout());
        this.add(paneles, BorderLayout.CENTER);
    }

    /**
     * Adds a new agent to the list of agents in the graphic interface
     * @param o Agent given
     */
    public void setJListModel(Object o) {
        pTraces.setJListModel(o);        
    }

    /**
     * Procedure that adds the name of a given agent to the list of agents of the graphic interface
     * @param o The given agent
     */
    public void addAgentToListModel(Object o) {
        pDebug.setJListModel(o);
    }

    /**
     * Adds a complete trace (src,msg,lvl,ts) to the table in the graphic interface
     * @param data Complete trace to show
     */
    public void addTrace(String[] data) {
        pTraces.addTrace(data);

    }

    // <editor-fold defaultstate="collapsed" desc="Getters">
    /**
     *
     * @return
     */
    public JPanel getTracesPanel(){
        return tracesPanel.getInstance(hc);
    }

    public JPanel getDebugPanel(){
        return pDebug;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Atributes">
     private static iconFactory ic = new iconFactory();
    private static horrorControlGraphics instance = null;
    private tracesPanel pTraces;
    private debugPanel pDebug;
//    private debugPanel  pDebug;
//    private exceptionPanel pExc;
//    private loaderPanel pLoader;
//    private statsPanel pStats;

    private JPanel pExc,pLoader,pStats;
    private JTabbedPane paneles;
    private Dimension tamPanel = new Dimension(400, 500);
    private static HorrorControl hc = null;

    // </editor-fold>
    
}
